<template>
  <div class="app-container">
    <uc-table url="admin/inAgency/getInAgencyPage" ref="agencyTable" name="待办事项" table-border pageable :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择责任企业" style="width: 100%" clearable  @clear="clearInput()" v-if="enterPriseHidden">
              <el-option v-for="(item,index) in enterpriseDominantList" :key="index"  :value="item.ucId" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <!--搜索按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="enterpriseName" label="所属主体" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="userName" label="待办人" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="noticeTime" label="通知时间" align="left" :show-overflow-tooltip="true">
            <template slot-scope="scope">
                {{scope.row.noticeTime | dateFormat}}
            </template>
        </el-table-column>
        <el-table-column prop="status" label="待办状态" align="left" :show-overflow-tooltip="true">
            <template slot-scope="scope">
                {{scope.row.status | agencyStatus}}
            </template>
        </el-table-column>
        <el-table-column prop="content" label="详细内容" align="left" :show-overflow-tooltip="true"></el-table-column>
<!--        <el-table-column prop="remark" label="描述" align="left" :show-overflow-tooltip="true"></el-table-column>-->
<!--        <el-table-column prop="agencyId" label="代办Id" align="left" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="address" label="操作" width="180" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
    </div>
</template>
<script>
import UcTable from "@/components/UcTable/index.vue";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";
import {removeInAgency, updateAgencyStatus} from "@/api/agency";


export default {

  name: "list",
  components: {UcTable},
  data(){
    return{
      searchForm:{

      },
      enterpriseDominantList:[],
      deleteLoading:false,
    }
  },
  created() {
    this.getInEnterpriseDominantList()
  },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"||roleCode=="XZ-ADMIN"
    }
  },
  methods: {
    clearInput(){
      //清除输入框
      this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    handleSearch(){

      this.$refs.agencyTable.getTableData(1)
    },
    getInEnterpriseDominantList(){
      getInEnterpriseDominantList({deleted:false}).then(res=>{
        this.enterpriseDominantList = res.data
      }).catch(error=>{

      })
    },
    handleInfo(val) {
        // updateAgencyStatus({ucId:val.ucId}).then(res=>{
        //     this.$router.push("/taskManage/agencyInfo?ucId="+val.ucId)
        // }).catch(error=>{
        //     console.log(error)
        // })
      console.log(val)
      switch (val.type){
        case  0:
          this.$router.push("/nonEmergency/hiddenDangerInfo?ucId=" + val.agencyId)
          break;
        case  1:
          this.$router.push("/workOrder/maintenanceInfo?ucId=" + val.agencyId)
          break;
        case  2:
          this.$router.push("/maintenance/maintenanceTaskInfo?ucId=" + val.agencyId+"&qyId="+val.enterpriseId)
          break;
        case  3:
          this.$router.push("/maintenance/checkRecordsInfo?ucId=" + val.agencyId)
          break;
        case  4:
          this.$router.push("/fireAlarm/fireInfoInfo/"+val.agencyId)
          break;
        case  5:
          this.$router.push("/maintenance/checkRecordsInfo?ucId=" + val.agencyId)
          break;
        default :
          break;
      }
    },
    handleDelete(val) {
      this.$confirm('您确定要执行删除' + val.name + '这条待办事项吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        removeInAgency(val).then(res => {
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除待办事项成功"
          })
         this.handleSearch()
        }).catch(res => {
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  }
}
</script>

<style
    scoped>

</style>
